{include file="admin/header.tpl" title="header" }
<script src="{$baseurl}/javascript/daily_sale.js"></script>

<div id="hidden_bill_row" style="display:none">
<div>
    <input maxlength="10" type="text" name="bill_paid[]" value="{$post.bill_paid}" style="width:80px" onkeypress="return intOnly(this,event);"  /> 
     <select name="company_id[]" style="width:150px;">
        <option value=""> select company </option>
        {foreach from=$companies item=row}
           <option  {if $post.company_id eq $row.company_id} selected="selected" {/if} value="{$row.company_id}" >{$row.company_name}</option>
        {/foreach}
     </select> <a href="#" onclick="removeBillRow(this)">Remove</a> 
     </div>
</div>             

<div id="content"> {php} echo display_msg(); {/php}
  <div class="error" id="main_error_div" style="display:none;"></div>
  
  {if !isset($post.sale_id) }
  <h2>Add Daily Sale</h2>
  <div class="lstable2">
    <form method="post" onsubmit="return formValidate('add');">
      <input type="hidden" name="action" id="action" value="{$post.action}">
      <table width="80%" border="0" cellspacing="0" cellpadding="4">
       <tr>
          <td width="20%" align="left" valign="middle"><strong>Super Mercado :</strong></td>
          <td width="70%" align="left" valign="middle">
          	{$session.store_name}
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        <tr>
          <td width="20%" align="left" valign="middle"><strong>Fecha : <span class="mandatory">*</span></strong></td>
          <td width="70%" align="left" valign="middle">
          	<input style="width:80px;" class="datePicker" readonly="readonly" type="text" name="sale_date" id="sale_date" value="{$post.sale_date}" />
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        <tr>
          <td width="20%" align="left" valign="middle"><strong>Diario Total :</strong></td>
          <td width="70%" align="left" valign="middle">
          	<input maxlength="10" type="text" id="total_sale" style="width:80px" readonly="readonly" /> 
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        <tr>
          <td width="20%" align="left" valign="middle"><strong>Effectivo :</strong></td>
          <td width="70%" align="left" valign="middle">
          	<input maxlength="10"  type="text" name="sale_cash" id="sale_cash" style="width:80px" onkeyup="updateTotal();"  value="{$post.sale_cash}" onkeypress="return intOnly(this,event);"  /> 
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        <tr>
          <td width="20%" align="left" valign="middle"><strong>Terjeta Credito :</strong></td>
          <td width="70%" align="left" valign="middle">
          	<input maxlength="10" type="text" name="sale_credit" id="sale_credit" style="width:80px" onkeyup="updateTotal();"  value="{$post.sale_credit}" onkeypress="return intOnly(this,event);"  /> 
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        <tr>
          <td width="20%" align="left" valign="top"><strong>Factura Pagado :</strong></td>
          <td width="70%" align="left" valign="top"> 
          <div id="div_bill_paid" class="div_bill_paid">
            <div>
            {foreach from=$companies item=row}
            <div style="padding:1px;">	
            	<input class="" maxlength="10" type="text" id="bill_paid_{$row.company_id}" name="bill_paid[]" value="{$post.bill_paid}" style="width:80px" onkeyup="updateTotal();" onkeypress="return intOnly(this,event);"  /> 
                <input type="hidden" name="company_id[]" value="{$row.company_id}"  /> &nbsp;  {$row.company_name}
                <input type="checkbox" onclick="checkVAT(this,{$row.company_id})" name="bill_paid_with_vat_{$row.company_id}" /> (check if paid with IVA)
                <input type="text" id="vat_{$row.company_id}" name="vat_{$row.company_id}" style="width:50px; display:none;" onkeypress="return intOnly(this,event);"  /> 
             </div>   
            {/foreach}
             </div>
           </div>
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
         <tr>
          <td width="20%" align="left" nowrap="nowrap" valign="middle"><strong> Total Factura Pagado :</strong></td>
          <td width="70%" align="left" valign="middle">
          	<input maxlength="10" type="text" id="total_bill_paid" style="width:80px" value="{$total_bill_paid}" readonly="readonly"/> 
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
         <tr>
          <td width="20%" align="left" valign="middle"><strong>Banco :</strong></td>
          <td width="70%" align="left" valign="middle">
          	<input maxlength="10" type="text" name="cash_left" id="cash_left" readonly="readonly" style="width:80px" value="{$post.cash_left}" onkeypress="return intOnly(this,event);"  /> 
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td  colspan="2" align="left"><input name="submit" class="btncss" type="submit" value="Save" />
            &nbsp;
            <input class="btncss" type="button" onclick="location.href='{$baseurl}/admin/daily_sale.php'" value="Cancel" /></td>
        </tr>
      </table>
    </form>
  </div>
  {else}
   <h2>Edit Sale</h2>
  <div class="lstable2">
    <form method="post" onsubmit="return photoValidate('edit');">
      <input type="hidden" name="action" id="action" value="edit">
      <input type="hidden" name="sale_id" id="sale_id" value="{$sale.sale_id}">
      <table width="80%" border="0" cellspacing="0" cellpadding="4">
       
       
       <tr>
          <td width="20%" align="left" valign="middle"><strong>Super Mercado :</strong></td>
          <td width="70%" align="left" valign="middle">
          	{$sale.store_name}
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        
        <tr>
          <td width="20%" align="left" valign="middle"><strong>Fecha : <span class="mandatory">*</span></strong></td>
          <td width="70%" align="left" valign="middle">
          	<input style="width:80px;" class="datePicker" readonly="readonly" type="text" name="sale_date" id="sale_date" value="{$sale.sale_date}" />
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        <tr>
          <td width="20%" align="left" valign="middle"><strong>Diario Total :</strong></td>
          <td width="70%" align="left" valign="middle">
          	<input maxlength="10" type="text" id="total_sale" style="width:80px" readonly="readonly" value="{$sale.total_sale}" /> 
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        <tr>
          <td width="20%" align="left" valign="middle"><strong>Effectivo :</strong></td>
          <td width="70%" align="left" valign="middle">
          	<input maxlength="10" type="text" name="sale_cash" id="sale_cash" style="width:80px" value="{$sale.sale_cash}" onkeyup="updateTotal();"  onkeypress="return intOnly(this,event);"  /> 
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        
        <tr>
          <td width="20%" align="left" valign="middle"><strong>Terjeta Credito :</strong></td>
          <td width="70%" align="left" valign="middle">
          	<input maxlength="10" type="text" name="sale_credit" id="sale_credit" style="width:80px" value="{$sale.sale_credit}"  onkeyup="updateTotal();" onkeypress="return intOnly(this,event);"  /> 
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        
        <tr>
          <td width="20%" align="left" valign="top"><strong>Factura Pagado :</strong></td>
          <td width="70%" align="left" valign="top"> 
          	<div id="div_bill_paid">
           	{assign var='total_bill_paid' value=0} 
            {foreach from=$sale.bill_paid_detail item=bill_row}
             {assign var='total_bill_paid' value=$total_bill_paid+$bill_row.bill_paid}
            <div style="padding:1px;">	
            	<input class="{if $bill_row.paid_with_vat eq '1'} txtColor {/if}" maxlength="10" type="text" name="bill_paid[]" id="bill_paid_{$bill_row.company_id}"  value="{$bill_row.bill_paid}" style="width:80px" onkeyup="updateTotal();" onkeypress="return intOnly(this,event);"  /> 
                <input type="hidden" name="company_id[]" value="{$bill_row.company_id}"  /> &nbsp; <strong> {$bill_row.company_name}</strong>
                <input type="checkbox" {if $bill_row.paid_with_vat eq '1'} checked="checked" {/if} onclick="checkVAT(this,{$bill_row.company_id})" name="bill_paid_with_vat_{$bill_row.company_id}" /> (check if paid with IVA)
                <input type="text" id="vat_{$bill_row.company_id}" name="vat_{$bill_row.company_id}" value="{$bill_row.vat}" style="width:50px; {if $bill_row.paid_with_vat ne '1'} display:none; {/if} " onkeypress="return intOnly(this,event);"  /> 
             </div>   
            {/foreach}
           <div> 
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        
         <tr>
          <td width="20%" align="left"  nowrap="nowrap" valign="middle"><strong> Total Factura Pagado :</strong></td>
          <td width="70%" align="left" valign="middle">
          	<input maxlength="10" type="text" id="total_bill_paid" style="width:80px" value="{$total_bill_paid}" readonly="readonly"/> 
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        
       <tr>
          <td width="20%" align="left" valign="middle"><strong>Banco :</strong></td>
          <td width="70%" align="left" valign="middle">
          	<input maxlength="10" type="text" name="cash_left"  readonly="readonly" id="cash_left" style="width:80px" value="{$sale.cash_left}" onkeypress="return intOnly(this,event);"  /> 
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td  colspan="2" align="left"><input name="submit" class="btncss" type="submit" value="Save" />
            &nbsp;
            <input class="btncss" type="button" onclick="location.href='{$baseurl}/admin/daily_sale.php'" value="Cancel" /></td>
        </tr>
      </table>
    </form>
  </div>
  			
        
         <script language="javascript">
			current_day = '{$smarty.now|date_format:"%d"}';
			current_month = '{$smarty.now|date_format:"%m"}';
			current_year = '{$smarty.now|date_format:"%Y"}';
		 {literal}
                  $('#sale_date').datepicker({minDate: new Date(1970, 1 - 1, 26),
			maxDate: new Date(current_year, current_month - 1, current_day)});
		{/literal}	
        </script>
  		 
  
  {/if} 
  </div>
{include file="admin/footer.tpl" title="footer"} 